Quiz: Garbage Collection

To View Tricks: Login Required

Number of Questions: 13

Question: 1 -

Which of the below is not a Java Profiler?

Options:
  1. JProfiler

  2. JVM

  3. Eclipse Profiler

  4. JConsole

  5. Answer:

    JVM

    Solution:

    Memory leak is like holding a strong reference to an object although it would never be needed anymore. Objects that are reachable but not live are considered memory leaks. Various tools help us to identify memory leaks.


Question: 2 -

How to get prints of shared object memory maps or heap memory maps for a given process?

Options:
  1. jmap

  2. memorypath

  3. memorymap

  4. jvmmap

  5. Answer:

    jmap

    Solution:

    We can use jmap as jmap -J-d64 -heap pid.


Question: 3 -

What is -Xms and -Xmx while starting jvm?

Options:
  1. Maximum; Initial memory

  2. Maximum memory

  3. Initial memory

  4. Initial; Maximum memory

  5. Answer:

    Initial; Maximum memory

    Solution:

    JVM will be started with Xms amount of memory and will be able to use a maximum of Xmx amount of memory. java -Xmx2048m -Xms256m.


Question: 4 -

Which of the below is not a memory leak solution?

Options:
  1. JVM parameter tuning

  2. GC parameter tuning

  3. Code changes

  4. Process restart

  5. Answer:

    Process restart

    Solution:

    Process restart is not a permanent fix to memory leak problem. The problem will resurge again.


Question: 5 -

What allows the programmer to destroy an object x?

Options:
  1. Runtime.getRuntime().gc()

  2. x.finalize()

  3. Only the garbage collection system can destroy an object

  4. x.delete()

  5. Answer:

    Only the garbage collection system can destroy an object

    Solution:

    When an object is no longer referenced, it may be reclaimed by the garbage collector. If an object declares a finalizer, the finalizer is executed before the object is reclaimed to give the object a last chance to clean up resources that would not otherwise be released. When a class is no longer needed, it may be unloaded.